# -*- coding: utf-8 -*-

import pydot
from sets import Set

graph = pydot.Dot(graph_type='digraph')


# http://www.graphviz.org/doc/info/attrs.html
# http://www.graphviz.org/Documentation.php

f = open("mensajes.txt")

nodos = {}
agregados = Set()

def newNode(addr):
	node = pydot.Node(addr)
	nodos[addr] = node		
	graph.add_node(node)

	return node
	
	

def getNode(addr):
	if addr in nodos.keys():
		node = nodos[addr]
	else:
		node = newNode(addr)
	return node


for l in f:
	words = l.split(" ")
	from_addr = words[2].strip()
	to_addr = words[4].strip()
	
	from_node = getNode(from_addr)
	to_node = getNode(to_addr)
	
	edge = from_addr + ":" + to_addr
	if not edge in agregados:
		graph.add_edge(pydot.Edge(from_node, to_node))
		agregados.add(edge)

graph.write_png('graph.png')

